<?php
/**
 * Created by PhpStorm.
 * Time: 下午5:02
 */


namespace swf\syncdb;

use swf\core\Config;

class Mysql{
    private static $instance = null;
    private static $mysql;
    private function __construct($config = null){
        $mysql = new \PDO(
            "mysql:host=localhost;port=3306;dbname=test",
            "root",
            "root",
            array(
                \PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8';",
                \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
                \PDO::ATTR_PERSISTENT => true
            )
        );
        self::$mysql = $mysql;

    }

    public static function getDb($config = null)
    {
        if(empty($instance))
        {
            self::$instance = new self($config);
        }
        return self::$mysql;
    }

    public function query($sql,$param)
    {
        $statement = self::$mysql->prepare($sql);
        $statement->execute($param);
        $result = $statement->fetchAll(\PDO::FETCH_ASSOC);
        return $result;
    }

}